var t = require("../../utils/config"), e = require("../../utils/request"), a = require("../../utils/api");

Page({
    data: {
        themeColor: getApp().globalData.themeColor,
        active: 0,
        list: [ t.resourceRoot + "icon-report.png" ],
        reservationList: [],
        reservation1: [],
        reservation2: [],
        reservation3: [],
        reservation4: [],
        reservation5: []
    },
    onLoad: function(t) {
        this.setData({
            active: parseInt(t.active)
        });
    },
    onShow: function() {
        this.selectReservationList();
    },
    onTagChange: function(t) {
        this.setData({
            active: parseInt(t.detail.name)
        }), this.selectReservationList();
    },
    filterReservationList: function() {
        switch (this.data.active) {
          case 1:
            var t = this.data.reservationList.filter(function(t) {
                return parseInt(t.payState) < 20 && parseFloat(t.totalFee) > 0;
            });
            this.setData({
                reservation1: t
            });
            break;

          case 2:
            var e = this.data.reservationList.filter(function(t) {
                return 1 == parseInt(t.status);
            });
            this.setData({
                reservation2: e
            });
            break;

          case 3:
            var a = this.data.reservationList.filter(function(t) {
                return parseInt(t.status) >= 2;
            });
            this.setData({
                reservation3: a
            });
            break;

          case 4:
            var s = this.data.reservationList.filter(function(t) {
                return 20 == parseInt(t.payState) && parseInt(t.status) >= 2;
            });
            this.setData({
                reservation5: s
            });
        }
    },
    selectReservationList: function() {
        var s = this;
        e.request(e.HttpMethod.GET, a.apiRoute.getResevationListByUid, {}).then(function(e) {
            e.success ? (e.data.forEach(function(e) {
                e.url = t.resourceRoot + "icon-report.png", null == e.payStateName && (e.payStateName = "无需支付"), 
                null == e.totalFee && (e.totalFee = 0), parseInt(e.payState) < 20 ? e.toDo = "去付款" : 20 == parseInt(e.payState) && parseInt(e.status) >= 2 ? e.toDo = "开票" : e.toDo = "查看";
            }), s.setData({
                reservationList: e.data
            }), s.filterReservationList()) : console.log("2");
        });
    }
});